home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / Q-R / QDPat.cpt / Draw_Quickly.Pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-01-08  |  10.5 KB  |  270 lines  |  [TEXT/PJMM]

  1. {The Project should have the following files in it:     }
  2. {     µRunTime.lib     LSP This is for main Pascal runtime library}
  3. {     Interface.lib      LSP This is the Mac trap interfaces}
  4. {     PrintCalls.Lib    LSP This is the print routine library interface}
  5. {     MacPrint.p        LSP This is the print equates for print calls}
  6. {     InitTheMenus.Pas      This initializes the Menus.}
  7. {     Dialog_2       Modal Dialog}
  8. {     Dialog_1       Modal Dialog}
  9. {    HandleTheMenus         Handle the menu selections.}
  10. {Set  RUN OPTIONS to use the  resource file Draw_Quickly.RSRC  }
  11. { RMaker file to use is Draw_Quickly.R  }
  12. {   Draw_Quickly.Pas      Main program  }
  13. program Draw_Quickly;
  14. {Program name:  Draw_Quickly.Pas  }
  15. {Function:  This is the main module for this program.  }
  16. {History: 10/6/89 Original by Prototyper.   }
  17. {                       }
  18.     uses
  19.         Dialog_2, Dialog_1, InitTheMenus, Globals, HandleTheMenus, Utilities, DrawMondrian, MenuUtilities;
  20.     var                                 {Main variables}
  21.         myEvent: EventRecord;          {Event record for all events}
  22.         doneFlag: boolean;             {Exit program flag}
  23.         code: integer;                 {Determine event type}
  24.         whichWindow: WindowPtr;        {See which window for event}
  25.         tempRect, OldRect: Rect;        {Rect for dragging}
  26.         mResult: longint;              {Menu list and item selected values}
  27.         theMenu, theItem: integer;{Menu list and item selected}
  28.         chCode: integer;               {Key code}
  29.         ch: char;                      {Key pressed in Ascii}
  30.         theInput: TEHandle;              {Used in text edit selections}
  31.         myPt: Point;                     {Temp Point, used in Zoom}
  32.         fullScreen: rect;
  33.         HowWide, HowHigh: Integer;
  34.  
  35. begin                               {Start of main body}
  36.  
  37.     MoreMasters;                    {This reserves space for more handles}
  38.     InitGraf(@thePort);             {Quickdraw Init}
  39.     InitFonts;                      {Font manager init}
  40.     InitWindows;                    {Window manager init}
  41.     InitMenus;                      {Menu manager init}
  42.     TEInit;                         {Text edit init}
  43.     InitDialogs(nil);               {Dialog manager}
  44.  
  45.     FlushEvents(everyEvent, 0);{Clear out all events}
  46.     InitCursor;                     {Make an arrow cursor}
  47.  
  48.     doneFlag := FALSE;              {Do not exit program yet}
  49.     NotInDA := true;
  50.  
  51.  
  52.     theInput := nil;                  {Init to no text edit selection active}
  53.     with ScreenBits.bounds do
  54.         begin
  55.             HowWide := right - left;
  56.             HowHigh := bottom - top;
  57.         end;
  58.     SetRect(fullScreen, 0, 0, (HowWide + 48), (HowHigh + 8));
  59.     SetDrawingRect(fullScreen);
  60.     ShowDrawing;
  61.     D_Dialog_1;
  62.     ShowDrawing;
  63.     Init_My_Menus;                  {Initialize menu bar}
  64.     WhichShape := Rectangle;
  65.  
  66.  
  67.  
  68.  
  69.     repeat                          {Start of main event loop}
  70.         if FrontWindow = nil then
  71.             begin
  72.                 DisableItem(M_File, 1);
  73.                 DisableItem(M_File, 3);
  74.                 DisableItem(M_File, 4);
  75.                 DisableItem(M_File, 5);
  76.                 DisableItem(M_File, 7);
  77.                 DisableItem(M_File, 8);
  78.                 DisableItem(M_Edit, 1);
  79.                 DisableItem(M_Edit, 2);
  80.                 DisableItem(M_Edit, 3);
  81.                 DisableItem(M_Edit, 4);
  82.                 NotInDA := true;
  83.             end;
  84.  
  85.         if (theInput <> nil) then{See if a TE is active}
  86.             TEIdle(theInput);       {Blink the cursor if everything is ok}
  87.         SystemTask;                 {For support of desk accessories}
  88.  
  89.         if GetNextEvent(everyEvent, myEvent) then{If event then...}
  90.             if BitAnd(myEvent.modifiers, $0001) <> 0 then
  91.                 begin
  92.                     DisableItem(M_File, 1);
  93.                     DisableItem(M_File, 3);
  94.                     DisableItem(M_File, 4);
  95.                     DisableItem(M_File, 5);
  96.                     DisableItem(M_File, 7);
  97.                     DisableItem(M_File, 8);
  98.                     DisableItem(M_Edit, 1);
  99.                     DisableItem(M_Edit, 2);
  100.                     DisableItem(M_Edit, 3);
  101.                     DisableItem(M_Edit, 4);
  102.                     NotInDA := true;
  103.                 end;
  104.  
  105.  
  106.         begin                       {Start handling the event}
  107.             code := FindWindow(myEvent.where, whichWindow);{Get which window the event happened in}
  108.             SystemTask;
  109.  
  110.  
  111.             case myEvent.what of{Decide type of event}
  112.                 MouseDown:         {Mouse button pressed}
  113.                     begin               {Handle the pressed button}
  114.                         SystemTask;
  115.                         if (code = inMenuBar) then{See if a menu selection}
  116.                             begin           {Get the menu selection and handle it}
  117.                                 SystemTask;
  118.                                 mResult := MenuSelect(myEvent.Where);{Do menu selection}
  119.                                 theMenu := HiWord(mResult);{Get the menu list number}
  120.                                 theItem := LoWord(mResult);{Get the menu list item number}
  121.                                 Handle_My_Menu(doneFlag, theMenu, theItem, theInput);{Handle the menu}
  122.                             end;            {End of inMenuBar}
  123.  
  124.                         if (code = InDrag) then{See if in a window drag area}
  125.                             begin           {Do dragging the window}
  126.                                 tempRect := screenbits.bounds;{Get screen area,  l,t,r,b, drag area}
  127.                                 SetRect(tempRect, tempRect.Left + 10, tempRect.Top + 25, tempRect.Right - 10, tempRect.Bottom - 10);{}
  128.                                 DragWindow(whichWindow, myEvent.where, tempRect);{Drag the window}
  129.                             end;            {End of InDrag}
  130.  
  131.                         if ((code = inGrow) and (whichWindow <> nil)) then{In a grow area of the window}
  132.                             begin           {Handle the growing}
  133.                                 SetPort(whichWindow);{Get ready to draw in this window}
  134.  
  135.                                 myPt := myEvent.where;{Get mouse position}
  136.                                 GlobalToLocal(myPt);{Make it relative}
  137.  
  138.                                 OldRect := WhichWindow^.portRect;{Save the rect before resizing}
  139.  
  140.                                 with screenbits.bounds do{use the screens size}
  141.                                     SetRect(tempRect, 15, 15, (right - left), (bottom - top) - 20);{l,t,r,b}
  142.                                 mResult := GrowWindow(whichWindow, myEvent.where, tempRect);{Grow it}
  143.                                 SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);{Resize to result}
  144.  
  145.  
  146.                                 SetPort(whichWindow);{Get ready to draw in this window}
  147.  
  148.                                 SetRect(tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15); {Position for horz scrollbar area}
  149.                                 EraseRect(tempRect);{Erase old area}
  150.                                 InvalRect(tempRect);{Flag us to update it}
  151.                                 SetRect(tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15);  {Position for vert scrollbar area}
  152.                                 EraseRect(tempRect);{Erase old area}
  153.                                 InvalRect(tempRect);{Flag us to update it}
  154.                                 DrawGrowIcon(whichWindow);{Draw the grow Icon again}
  155.                             end;            {End of doing the growing}
  156.  
  157.                         if (code = inZoomIn) or (code = inZoomOut) then{Handle Zooming windows}
  158.                             begin           {}
  159.                                 if (WhichWindow <> nil) then{See if we have a legal window}
  160.                                     begin       {}
  161.                                         SetPort(whichWindow);{Get ready to draw in this window}
  162.  
  163.                                         myPt := myEvent.where;{Get mouse position}
  164.                                         GlobalToLocal(myPt);{Make it relative}
  165.  
  166.                                         OldRect := whichWindow^.portRect;{Save the rect before resizing}
  167.  
  168.                                         if TrackBox(whichWindow, myPt, code) then{Zoom it}
  169.                                             begin{}
  170.                                                 ZoomWindow(WhichWindow, code, TRUE);{Resize to result}
  171.                                                 SetRect(tempRect, 0, 0, 32000, 32000);{l,t,r,b}
  172.                                                 EraseRect(tempRect);{Make sure we update the whole window effectively}
  173.                                                 InvalRect(tempRect);{Tell ourselves to update, redraw, the window contents}
  174.                                             end;{}
  175.                                     end;        {}
  176.                             end;            {}
  177.  
  178.                         if (code = inGoAway) then{See if in a window goaway area}
  179.                             begin           {Handle the goaway button}
  180.                                 if TrackGoAway(whichWindow, myEvent.where) then{See if mouse released in GoAway box}
  181.                                     begin       {Handle the GoAway}
  182.                                     end;        {End of TrackGoAway}
  183.                             end;            {End of InGoAway}
  184.  
  185.                         if (code = inContent) then{See if in a window}
  186.                             begin           {Handle the hit inside a window}
  187.                                 if (whichWindow <> FrontWindow) then{See if already selected or not, in front if selected}
  188.                                     SelectWindow(whichWindow){Select this window to make it active}
  189.                                 else        {If already in front the already selected}
  190.                                     begin       {Handle the button in the content}
  191.                                         SetPort(whichWindow);{Get ready to draw in this window}
  192.                                     end;        {End of else}
  193.                             end;            {End of inContent}
  194.  
  195.                         if (code = inSysWindow) then{See if a DA selection}
  196.                             SystemClick(myEvent, whichWindow);{Let other programs in}
  197.                         SystemTask;
  198.  
  199.                     end;                {End of MouseDown}
  200.  
  201.                 KeyDown, AutoKey:{Handle key inputs}
  202.                     begin               {Get the key and handle it}
  203.                         with myevent do{Check for menu command keys}
  204.                             begin           {}
  205.                                 chCode := BitAnd(message, CharCodeMask);{Get character}
  206.                                 ch := CHR(chCode);{Change to ASCII}
  207.                                 if (Odd(modifiers div CmdKey)) then{See if Command key is down}
  208.                                     begin       {}
  209.                                         mResult := MenuKey(ch);{See if menu selection}
  210.                                         theMenu := HiWord(mResult);{Get the menu list number}
  211.                                         theItem := LoWord(mResult);{Get the menu item number}
  212.                                         if (theMenu <> 0) then{See if a list was selected}
  213.                                             Handle_My_Menu(doneFlag, theMenu, theItem, theInput);{Do the menu selection}
  214.                                         if ((ch = 'x') or (ch = 'X')) and (theInput <> nil) then{}
  215.                                             TECut(theInput);{Handle a Cut in a TE area}
  216.                                         if ((ch = 'c') or (ch = 'C')) and (theInput <> nil) then{}
  217.                                             TECopy(theInput);{Handle a Copy in a TE area}
  218.                                         if ((ch = 'v') or (ch = 'V')) and (theInput <> nil) then{}
  219.                                             TEPaste(theInput);{Handle a Paste in a TE area}
  220.                                     end         {}
  221.                                 else if (theInput <> nil) then{}
  222.                                     TEKey(ch, theInput);{}
  223.                             end;            {}
  224.                     end;                {End for KeyDown,AutoKey}
  225.  
  226.                 UpDateEvt:         {Update event for a window}
  227.                     begin               {Handle the update}
  228.                         whichWindow := WindowPtr(myEvent.message);{Get the window the update is for}
  229.                         BeginUpdate(whichWindow);{Set the clipping to the update area}
  230.                         EndUpdate(whichWindow);{Return to normal clipping area}
  231.                     end;                {End of UpDateEvt}
  232.  
  233.                 DiskEvt:           {Disk inserted event}
  234.                     begin               {Handle a disk event}
  235.                         if (HiWord(myevent.message) <> noErr) then{See if a diskette mount error}
  236.                             begin           {due to unformatted diskette inserted}
  237.                                 myEvent.where.h := ((screenbits.bounds.Right - screenbits.bounds.Left) div 2) - (304 div 2);{Center horz}
  238.                                 myEvent.where.v := ((screenbits.bounds.Bottom - screenbits.bounds.Top) div 3) - (104 div 2);{Top 3ed vertically}
  239.                                 InitCursor;{Make sure it has an arrow cursor}
  240.                                 chCode := DIBadMount(myEvent.where, myevent.message);{Let the OS handle the diskette}
  241.                             end;            {}
  242.                     end;               {End of DiskEvt}
  243.  
  244.                 ActivateEvt:       {Window activated event}
  245.                     begin               {Handle the activation}
  246.                         whichWindow := WindowPtr(myevent.message);{Get the window to be activated}
  247.                         if odd(myEvent.modifiers) then{Make sure it is Activate and not DeActivate}
  248.                             begin       {Handle the activate}
  249.                                 SelectWindow(whichWindow);{Activate the window by selecting it}
  250.                             end;        {End of Activate}
  251.                     end;                {End of ActivateEvt}
  252.  
  253.                 otherwise           {Used for debugging, to see what other events are coming in}
  254.                     begin               {}
  255.                         {?? ADDED FOR DEBUGGING, CATCHING OTHER EVENTS}
  256. {}
  257.                     end;                {End of otherwise}
  258.  
  259.             end;                    {End of case}
  260.  
  261.         end;                        {end of GetNextEvent}
  262.         SystemTask;
  263.         if NotInDA then
  264.             begin
  265.                 DrawShapes(WhichShape);
  266.             end;
  267.  
  268.     until doneFlag;                 {End of the event loop}
  269.  
  270. end.                                    {End of the program}